﻿#define _DebugDrawBorder_uomBHP_ExpandClientRectange

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DienLib.SummitLib;
//using Excel = Microsoft.Office.Interop.Excel;
//using Word = Microsoft.Office.Interop.Word;
using System.Diagnostics;

namespace DienLib.SummitLib
{
    /// <summary>
    /// Wrapper for Summit New Job Form
    /// </summary>
    public class JobLib
    {
        #region Remote VARIABLE
        const string TOOLBAR_SAVE = "_tbSave";
        ToolBarButtonD a_tbbSave;
        const string TOOLBAR_CANCEL = "_TBB_Cancel";
        ToolBarButtonD a_tbbCancel;
        const string TOOLBAR_SAVE_EXIT = "_TBB_SaveAndExit";
        ToolBarButtonD a_tbbSaveExit;
        const string TOOLBAR_JOB_TIMES = "_TBB_JobTimes";
        ToolBarButtonD a_tbbJobTimes;
        const string TOOLBAR_JOB_MATERIALS = "_TBB_JobMaterials";
        ToolBarButtonD a_tbbJobMaterials;
        const string TOOLBAR_PERSONNEL_EDITOR = "_TBB_Personnel";
        ToolBarButtonD a_tbbPersonnel;
        const string TOOLBAR_EQUIPMENT_SELECTOR = "_TBB_EquipmentSelector";
        ToolBarButtonD a_tbbEquipmentSelector;
        const string TOOLBAR = "_ToolBar1";
        ToolBarD a_ToolBarTop;

        const string TABCONTROL = "_TabControl1";
        TabControlD a_TabControlMain;

        const string TABPAGE_1_HEADER_DATA = "_TabPage1";
        TabPageD a_TabPage1;
        const string TABPAGE_2_WELL_DATA = "_TabPage2";
        TabPageD a_TabPage2;
        const string TABPAGE_3_SERVICE_DELIVER = "_TabPage3";
        TabPageD a_TabPage3;
        const string TABPAGE_4_QUALITY_REVIEW = "_TabPage4";
        TabPageD a_TabPage4;
        const string TABPAGE_5_BILLING_TICKET = "_TabPage5";
        TabPageD a_TabPage5;

        const string TABPAGE1_UC_WELL_ID = "_UcWellIdentification1";
        UserControl a_ucWellIdentification;
        const string TABPAGE1_BUT_NEW_WELL = "_btnNewWell";
        ButtonD a_btnNewWell;
        const string TABPAGE1_COMBO_CO2_PRESENT = "_cboCo2Present";
        ComboBoxD a_cboCo2Present;
        const string TABPAGE1_COMBO_COUNTRY = "_cboCountry";
        ComboBoxD a_cboCountry;
        const string TABPAGE1_COMBO_STATE = "_cboState";
        ComboBoxD a_cboState;
        const string TABPAGE1_COMBO_FIELD = "_cboField";
        ComboBoxD a_cboField;
        const string TABPAGE1_COMBO_H2S_PRESENT = "_cboH2sPresent";
        ComboBoxD a_cboH2sPresent;
        const string TABPAGE1_COMBO_LEASE = "_cboLease";
        ComboBoxD a_cboLease;
        const string TABPAGE1_COMBO_LOCATION = "_cboLocation";
        ComboBoxD a_cboLocation;
        const string TABPAGE1_CHECKBOX_RIGLESS_OPERATION = "_chkRiglessOperation";
        CheckBoxD a_chkRiglessOperation;
        const string TABPAGE1_BUT_GET_API = "_btnDefaultAPI";
        ButtonD a_btnDefaultAPI;
        const string TABPAGE1_TEXT_WELL_NAME = "_txtWellName";
        TextBoxD a_txtWellName;
        const string TABPAGE1_TEXT_API_UWI = "_txtAPI";
        TextBoxD a_txtAPI;
        const string TABPAGE1_TEXT_SHIP_TO = "_txtSAPWellId";
        TextBoxD a_txtSAPWellId;

        const string TABPAGE1_UC_CUSTOMER_INFO = "_UcCustomerInfo1";
        UserControl a_UcCustomerInfo;
        const string TABPAGE1_COMBO_COMPANY = "_cboCompany";
        ComboBoxD a_cboCompany;
        const string TABPAGE1_COMBO_CUSTOMER_REP = "_cboCustomerRepDetails";
        ComboBoxD a_cboCustomerRepDetails;
        const string TABPAGE1_COMBO_ORDERED_BY = "_cboOrderedByDetails";
        ComboBoxD a_cboOrderedByDetails;
        const string TABPAGE1_COMBO_JOB_WELL_TYPE = "_cboJobWellType";
        ComboBoxD a_cboJobWellType;
        const string TABPAGE1_COMBO_PRIMARY_SERVICE_CENTER = "_cboPrimaryServiceCenter";
        ComboBoxD a_cboPrimaryServiceCenter;
        const string TABPAGE1_COMBO_SECOND_SERVICE_CENTER = "_cboSecondaryServiceCenter";
        ComboBoxD a_cboSecondaryServiceCenter;
        const string TABPAGE1_COMBO_JOB_TYPE = "_cboJobType";
        ComboBoxD a_cboJobType;
        const string TABPAGE1_COMBO_JOB_STATUS = "_cboCurrentJobStatus";
        ComboBoxD a_cboCurrentJobStatus;
        const string TABPAGE1_CHECKBOX_TRAINING_JOB = "_chkTrainingJob";
        CheckBoxD a_chkTrainingJob;
        const string TABPAGE1_TEXT_SALE_NUMBER = "_txtSalesOrderNumber";
        TextBoxD a_txtSalesOrderNumber;
        const string TABPAGE1_TEXT_QUOTE_NUMBER = "_txtQuoteNumber";
        TextBoxD a_txtQuoteNumber;
        const string TABPAGE1_TEXT_PHONE = "_txtPhone";
        LabelD a_lblPhone;
        const string TABPAGE1_TEXT_FAX = "_txtFax";
        LabelD a_lblFax;

        const string TABPAGE2_UC_WELL_DATA = "_UcLogJobWellDataCtrl";
        UserControl a_ucWellDataCtrl;

        const string TABPAGE2_LABEL_BHP = "_lblBHP";
        LabelD a_lblBHP;

        const string TABPAGE2_COMBO_WELL_FLUID = "_cboWellFluid";
        ComboBoxD a_cboWellFluid;
        const string TABPAGE2_CHECKBOX_SHOW_PERF_DATA = "_chkShowPerfData";
        CheckBoxD a_chkShowPerfData;
        const string TABPAGE2_DATAGRID_TUBING_ = "_dgTubPerf";
        DataGridD a_dgTubPerf;
        const string TABPAGE2_UTEXT_BHP = "_uomBHP";
        UnitTextBox a_uomBHP;
        const string TABPAGE2_UTEXT_BHT = "_uomBHT";
        UnitTextBox a_uomBHT;
        const string TABPAGE2_UTEXT_BIT_SIZE = "_uomBitSize";
        UnitTextBox a_uomBitSize;
        const string TABPAGE2_UTEXT_CAKE_RES = "_uomCakeResistivity";
        UnitTextBox a_uomCakeResistivity;
        const string TABPAGE2_UTEXT_CAKE_RES_MD = "_uomCakeResistivityMD";
        UnitTextBox a_uomCakeResistivityMD;
        const string TABPAGE2_UTEXT_CLO = "_uomChlorideConc";
        UnitTextBox a_uomChlorideConc;
        const string TABPAGE2_UTEXT_DEV_TD = "_uomDeviationTD";
        UnitTextBox a_uomDeviationTD;
        const string TABPAGE2_UTEXT_DRILLER_DEPTH = "_uomDrillerDepth";
        UnitTextBox a_uomDrillerDepth;
        const string TABPAGE2_UTEXT_FILTERATE_RES = "_uomFilterateResistivity";
        UnitTextBox a_uomFilterateResistivity;
        const string TABPAGE2_UTEXT_FILTERATE_RES_MD = "_uomFilterateResistivityMD";
        UnitTextBox a_uomFilterateResistivityMD;
        const string TABPAGE2_UTEXT_FLUIDLEVEL = "_uomFluidLevel";
        UnitTextBox a_uomFluidLevel;
        const string TABPAGE2_UTEXT_JOB_MD = "_uomJobMD";
        UnitTextBox a_uomJobMD;
        const string TABPAGE2_UTEXT_JOB_TVD = "_uomJobTVD";
        UnitTextBox a_uomJobTVD;
        const string TABPAGE2_UTEXT_KICK_DEPTH = "_uomKickDepth";
        UnitTextBox a_uomKickDepth;
        const string TABPAGE2_UTEXT_MAX_DEV = "_uomMaxDev";
        UnitTextBox a_uomMaxDev;
        const string TABPAGE2_UTEXT_MAX_DEV_MD = "_uomMaxDevMD";
        UnitTextBox a_uomMaxDevMD;
        const string TABPAGE2_UTEXT_MAX_DOGLEG = "_uomMaxDogLeg";
        UnitTextBox a_uomMaxDogLeg;
        const string TABPAGE2_UTEXT_MAX_DOGLEG_MD = "_uomMaxDogLegMD";
        UnitTextBox a_uomMaxDogLegMD;
        const string TABPAGE2_UTEXT_MIN_ID = "_uomMinID";
        UnitTextBox a_uomMinID;
        const string TABPAGE2_UTEXT_MIN_ID_MD = "_uomMinIDMD";
        UnitTextBox a_uomMinIDMD;
        const string TABPAGE2_UTEXT_MUD_RES = "_uomMudResistivity";
        UnitTextBox a_uomMudResistivity;
        const string TABPAGE2_UTEXT_MUD_RES_MD = "_uomMudResistivityMD";
        UnitTextBox a_uomMudResistivityMD;
        const string TABPAGE2_UTEXT_MUD_WEIGHT = "_uomMudWt";
        UnitTextBox a_uomMudWt;
        const string TABPAGE2_UTEXT_SEABED_TEMP = "_uomSeaBedTemp";
        UnitTextBox a_uomSeaBedTemp;
        const string TABPAGE2_UTEXT_WATER_DEPTH = "_uomWaterDepth";
        UnitTextBox a_uomWaterDepth;
        const string TABPAGE2_UTEXT_WELL_DIR_TD = "_uomWellDirTD";
        UnitTextBox a_uomWellDirTD;
        const string TABPAGE2_UTEXT_WHP = "_uomWHP";
        UnitTextBox a_uomWHP;

        const string TABPAGE2_UC_SERVICE_COORDINATOR = "_ServiceCoodinatorCtrl1";
        UserControl a_ucServiceCoordinatorCtrl;
        const string TABPAGE2_BUTTON_GENERATE_HIT_LIST = "_Btn_GenerateHitList";
        ButtonD a_Btn_GenerateHitList;
        const string TABPAGE2_COMBO_SERVICE_PLANNER = "_cmbServicePlanner";
        ComboBoxD a_cmbServicePlanner;
        const string TABPAGE2_COMBO_SERVICE_COORDINATOR = "_cmbSrvcCoord";
        ComboBoxD a_cmbSrvcCoord;

        const string TABPAGE3_UC_JOB_SUPERVISOR = "_JobSupervisor";
        UserControl a_ucJobSupervisor;
        const string TABPAGE3_BUTTON_EXPLOSIVE_SAFETY = "_btn_ExplosiveSafety";
        ButtonD a_btn_ExplosiveSafety;
        const string TABPAGE3_BUTTON_KPI = "_Btn_KpiEjcs";
        ButtonD a_Btn_KpiEjcs;
        const string TABPAGE3_BUTTON_SERVICE_DELIVERY = "_Btn_ServiceDeliveryDelivery";
        ButtonD a_Btn_ServiceDeliveryDelivery;
        const string TABPAGE3_BUTTON_PERFORATION = "_btnPerforation";
        ButtonD a_btnPerforation;
        const string TABPAGE3_BUTTON_SERVICES = "_btnServices";
        ButtonD a_btnServices;
        const string TABPAGE3_BUTTON_SAFETY = "_Btn_SafetygMeeting";
        ButtonD a_btnSafetyMeeting;
        const string TABPAGE3_COMBO_ENGINEER = "_Cbo_Engineer";
        ComboBoxD a_cboEngineer;
        const string TABPAGE3_COMBO_QUALITY_COORDINATOR = "_cboQualityCoordinator";
        ComboBoxD a_cboQualityCoordinator;
        const string TABPAGE3_DATAGRID_PERFORATION = "_dgPerforation";
        DataGridD a_dgPerforation;
        const string TABPAGE3_DATAGRID_SERVICES = "_dgServices";
        DataGridD a_dgServices;
        const string TABPAGE3_TABCONTROL_SERVICES = "_TabPage_Services";
        TabPageD a_TabPage_Services;
        #endregion

        private Form _form;
        public JobLib(Form NewJobForm)
        {
            if (NewJobForm == null) throw new NullReferenceException();
            if (NewJobForm.IsDisposed) throw new Exception("New Job Form already Disposed or Closed");
            this._form = NewJobForm;
            #region Init Remote Variable
            a_ToolBarTop = new ToolBarD(DienLib.Reflector.GetField<ToolBar>(_form, TOOLBAR));
            a_TabControlMain = new TabControlD(DienLib.Reflector.GetField<TabControl>(_form, TABCONTROL));

            a_tbbSave = new ToolBarButtonD(DienLib.Reflector.GetField<ToolBarButton>(_form, TOOLBAR_SAVE));
            a_tbbCancel = new ToolBarButtonD(DienLib.Reflector.GetField<ToolBarButton>(_form, TOOLBAR_CANCEL));
            a_tbbSaveExit = new ToolBarButtonD(DienLib.Reflector.GetField<ToolBarButton>(_form, TOOLBAR_SAVE_EXIT));
            a_tbbJobTimes = new ToolBarButtonD(DienLib.Reflector.GetField<ToolBarButton>(_form, TOOLBAR_JOB_TIMES));
            a_tbbJobMaterials = new ToolBarButtonD(DienLib.Reflector.GetField<ToolBarButton>(_form, TOOLBAR_JOB_MATERIALS));
            //ToolBarButton tb = DienLib.Reflector.GetField<ToolBarButton>(_form, TOOLBAR_PERSONNEL_EDITOR);
            //DienLib.WinAPI.WriteNotePad("KAKAKA : " + tb.ToString());
            a_tbbPersonnel = new ToolBarButtonD(DienLib.Reflector.GetField<ToolBarButton>(_form, TOOLBAR_PERSONNEL_EDITOR));
            a_tbbEquipmentSelector = new ToolBarButtonD(DienLib.Reflector.GetField<ToolBarButton>(_form, TOOLBAR_EQUIPMENT_SELECTOR));


            a_TabPage1 = new TabPageD(DienLib.Reflector.GetField<TabPage>(_form, TABPAGE_1_HEADER_DATA));
            a_TabPage2 = new TabPageD(DienLib.Reflector.GetField<TabPage>(_form, TABPAGE_2_WELL_DATA));
            a_TabPage3 = new TabPageD(DienLib.Reflector.GetField<TabPage>(_form, TABPAGE_3_SERVICE_DELIVER));
            a_TabPage4 = new TabPageD(DienLib.Reflector.GetField<TabPage>(_form, TABPAGE_4_QUALITY_REVIEW));
            a_TabPage5 = new TabPageD(DienLib.Reflector.GetField<TabPage>(_form, TABPAGE_5_BILLING_TICKET));

            // Controls in TabPage1 : UserControl ucWellIdentification
            a_ucWellIdentification = DienLib.Reflector.GetField<UserControl>(_form, TABPAGE1_UC_WELL_ID);
            a_btnNewWell = new ButtonD(DienLib.Reflector.GetField<Button>(a_ucWellIdentification, TABPAGE1_BUT_NEW_WELL));
            a_cboCo2Present = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucWellIdentification, TABPAGE1_COMBO_CO2_PRESENT));
            a_cboCountry = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucWellIdentification, TABPAGE1_COMBO_COUNTRY));
            a_cboState = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucWellIdentification, TABPAGE1_COMBO_STATE));
            a_cboField = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucWellIdentification, TABPAGE1_COMBO_FIELD));
            a_cboH2sPresent = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucWellIdentification, TABPAGE1_COMBO_H2S_PRESENT));
            a_cboLease = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucWellIdentification, TABPAGE1_COMBO_LEASE));
            a_cboLocation = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucWellIdentification, TABPAGE1_COMBO_LOCATION));
            a_chkRiglessOperation = new CheckBoxD(DienLib.Reflector.GetField<CheckBox>(a_ucWellIdentification, TABPAGE1_CHECKBOX_RIGLESS_OPERATION));
            a_btnDefaultAPI = new ButtonD(DienLib.Reflector.GetField<Button>(a_ucWellIdentification, TABPAGE1_BUT_GET_API));
            a_txtWellName = new TextBoxD(DienLib.Reflector.GetField<TextBox>(a_ucWellIdentification, TABPAGE1_TEXT_WELL_NAME));
            a_txtAPI = new TextBoxD(DienLib.Reflector.GetField<TextBox>(a_ucWellIdentification, TABPAGE1_TEXT_API_UWI));
            a_txtSAPWellId = new TextBoxD(DienLib.Reflector.GetField<TextBox>(a_ucWellIdentification, TABPAGE1_TEXT_SHIP_TO));
            // Controls in TabPage1 : UserControl ucCustomerInfo
            a_UcCustomerInfo = DienLib.Reflector.GetField<UserControl>(_form, TABPAGE1_UC_CUSTOMER_INFO);
            a_cboCompany = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_UcCustomerInfo, TABPAGE1_COMBO_COMPANY));
            a_cboCustomerRepDetails = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_UcCustomerInfo, TABPAGE1_COMBO_CUSTOMER_REP));
            a_cboOrderedByDetails = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_UcCustomerInfo, TABPAGE1_COMBO_ORDERED_BY));
            a_cboJobWellType = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_UcCustomerInfo, TABPAGE1_COMBO_JOB_WELL_TYPE));
            a_cboPrimaryServiceCenter = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_UcCustomerInfo, TABPAGE1_COMBO_PRIMARY_SERVICE_CENTER));
            a_cboSecondaryServiceCenter = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_UcCustomerInfo, TABPAGE1_COMBO_SECOND_SERVICE_CENTER));
            a_cboJobType = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_UcCustomerInfo, TABPAGE1_COMBO_JOB_TYPE));
            a_cboCurrentJobStatus = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_UcCustomerInfo, TABPAGE1_COMBO_JOB_STATUS));
            a_chkTrainingJob = new CheckBoxD(DienLib.Reflector.GetField<CheckBox>(a_UcCustomerInfo, TABPAGE1_CHECKBOX_TRAINING_JOB));
            a_txtSalesOrderNumber = new TextBoxD(DienLib.Reflector.GetField<TextBox>(a_UcCustomerInfo, TABPAGE1_TEXT_SALE_NUMBER));
            a_txtQuoteNumber = new TextBoxD(DienLib.Reflector.GetField<TextBox>(a_UcCustomerInfo, TABPAGE1_TEXT_QUOTE_NUMBER));
            a_lblPhone = new LabelD(DienLib.Reflector.GetField<Label>(a_UcCustomerInfo, TABPAGE1_TEXT_PHONE));
            a_lblFax = new LabelD(DienLib.Reflector.GetField<Label>(a_UcCustomerInfo, TABPAGE1_TEXT_FAX));
            // Controls in TabPage2 : UserControl ucLogJobWellData
            a_ucWellDataCtrl = DienLib.Reflector.GetField<UserControl>(_form, TABPAGE2_UC_WELL_DATA);

            a_lblBHP = new LabelD(DienLib.Reflector.GetField<Label>(a_ucWellDataCtrl, TABPAGE2_LABEL_BHP));

            a_cboWellFluid = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucWellDataCtrl, TABPAGE2_COMBO_WELL_FLUID));
            a_chkShowPerfData = new CheckBoxD(DienLib.Reflector.GetField<CheckBox>(a_ucWellDataCtrl, TABPAGE2_CHECKBOX_SHOW_PERF_DATA));
            a_dgTubPerf = new DataGridD(DienLib.Reflector.GetField<DataGrid>(a_ucWellDataCtrl, TABPAGE2_DATAGRID_TUBING_));

            a_uomBHP = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_BHP));

            a_uomBHT = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_BHT));
            a_uomBitSize = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_BIT_SIZE));
            a_uomCakeResistivity = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_CAKE_RES));
            a_uomCakeResistivityMD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_CAKE_RES_MD));
            a_uomChlorideConc = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_CLO));
            a_uomDeviationTD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_DEV_TD));
            a_uomDrillerDepth = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_DRILLER_DEPTH));
            a_uomFilterateResistivity = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_FILTERATE_RES));
            a_uomFilterateResistivityMD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_FILTERATE_RES_MD));
            a_uomFluidLevel = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_FLUIDLEVEL));
            a_uomJobMD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_JOB_MD));
            a_uomJobTVD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_JOB_TVD));
            a_uomKickDepth = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_KICK_DEPTH));
            a_uomMaxDev = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_MAX_DEV));
            a_uomMaxDevMD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_MAX_DEV_MD));
            a_uomMaxDogLeg = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_MAX_DOGLEG));
            a_uomMaxDogLegMD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_MAX_DOGLEG_MD));
            a_uomMinID = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_MIN_ID));
            a_uomMinIDMD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_MIN_ID_MD));
            a_uomMudResistivity = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_MUD_RES));
            a_uomMudResistivityMD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_MUD_RES_MD));
            a_uomMudWt = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_MUD_WEIGHT));
            a_uomSeaBedTemp = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_SEABED_TEMP));
            a_uomWaterDepth = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_WATER_DEPTH));
            a_uomWellDirTD = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_WELL_DIR_TD));
            a_uomWHP = new UnitTextBox(DienLib.Reflector.GetField<Control>(a_ucWellDataCtrl, TABPAGE2_UTEXT_WHP));
            // Controls in TabPage2 : UserControl _ServiceCoodinatorCtrl
            a_ucServiceCoordinatorCtrl = DienLib.Reflector.GetField<UserControl>(_form, TABPAGE2_UC_SERVICE_COORDINATOR);
            a_Btn_GenerateHitList = new ButtonD(DienLib.Reflector.GetField<Button>(a_ucServiceCoordinatorCtrl, TABPAGE2_BUTTON_GENERATE_HIT_LIST));
            a_cmbServicePlanner = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucServiceCoordinatorCtrl, TABPAGE2_COMBO_SERVICE_PLANNER));
            a_cmbSrvcCoord = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucServiceCoordinatorCtrl, TABPAGE2_COMBO_SERVICE_COORDINATOR));

            // Controls in TabPage3 : UserControl _JobSupervisor
            a_ucJobSupervisor = DienLib.Reflector.GetField<UserControl>(_form, TABPAGE3_UC_JOB_SUPERVISOR);
            a_btn_ExplosiveSafety = new ButtonD(DienLib.Reflector.GetField<Button>(a_ucJobSupervisor, TABPAGE3_BUTTON_EXPLOSIVE_SAFETY));
            a_Btn_KpiEjcs = new ButtonD(DienLib.Reflector.GetField<Button>(a_ucJobSupervisor, TABPAGE3_BUTTON_KPI));
            a_Btn_ServiceDeliveryDelivery = new ButtonD(DienLib.Reflector.GetField<Button>(a_ucJobSupervisor, TABPAGE3_BUTTON_SERVICE_DELIVERY));
            a_btnPerforation = new ButtonD(DienLib.Reflector.GetField<Button>(a_ucJobSupervisor, TABPAGE3_BUTTON_PERFORATION));
            a_btnServices = new ButtonD(DienLib.Reflector.GetField<Button>(a_ucJobSupervisor, TABPAGE3_BUTTON_SERVICES));
            a_btnSafetyMeeting = new ButtonD(DienLib.Reflector.GetField<Button>(a_ucJobSupervisor, TABPAGE3_BUTTON_SAFETY));
            a_cboEngineer = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucJobSupervisor, TABPAGE3_COMBO_ENGINEER));
            a_cboQualityCoordinator = new ComboBoxD(DienLib.Reflector.GetField<ComboBox>(a_ucJobSupervisor, TABPAGE3_COMBO_QUALITY_COORDINATOR));
            a_dgPerforation = new DataGridD(DienLib.Reflector.GetField<DataGrid>(a_ucJobSupervisor, TABPAGE3_DATAGRID_PERFORATION));
            a_dgServices = new DataGridD(DienLib.Reflector.GetField<DataGrid>(a_ucJobSupervisor, TABPAGE3_DATAGRID_SERVICES));
            a_TabPage_Services = new TabPageD(DienLib.Reflector.GetField<TabPage>(a_ucJobSupervisor, TABPAGE3_TABCONTROL_SERVICES));
            #endregion
        }

        public void ChoosePersonnel()
        {
            a_tbbPersonnel.PerformButtonClick();
        }
        public Enums.Customer Customer
        {
            get { return Enums.eCustomer.ToEnum(a_cboCompany.Text); }
            set { a_cboCompany.Text = Enums.eCustomer.ToData(value); }
        }
        public Enums.WellType WellType
        {
            get { return Enums.eWellType.ToEnum(a_cboJobWellType.Text); }
            set { a_cboJobWellType.Text = Enums.eWellType.ToData(value); }
        }
        public Enums.ServiceCenter PrimaryServiceCenter
        {
            get { return Enums.eServiceCenter.ToEnum(a_cboPrimaryServiceCenter.Text); }
            set { a_cboPrimaryServiceCenter.Text = Enums.eServiceCenter.ToData(value); }
        }
        public Enums.ServiceCenter SecondaryServiceCenter
        {
            get { return Enums.eServiceCenter.ToEnum(a_cboSecondaryServiceCenter.Text); }
            set { a_cboSecondaryServiceCenter.Text = Enums.eServiceCenter.ToData(value); }
        }
        public Enums.JobType JobType
        {
            get { return Enums.eJobType.ToEnum(a_cboJobType.Text); }
            set { a_cboJobType.Text = Enums.eJobType.ToData(value); }
        }
        public Enums.Location Location
        {
            get { return Enums.eLocation.ToEnum(a_cboLocation.Text); }
            set { a_cboLocation.Text = Enums.eLocation.ToData(value); }
        }
        public Enums.Country Country
        {
            get { return Enums.eCountry.ToEnum(a_cboCountry.Text); }
            set { a_cboCountry.Text = Enums.eCountry.ToData(value); }
        }
        public Enums.State State
        {
            get { return Enums.eState.ToEnum(a_cboState.Text); }
            set { a_cboState.Text = Enums.eState.ToData(value); }
        }
        public Enums.CO2Present CO2Present
        {
            get { return Enums.eCO2Present.ToEnum(a_cboCo2Present.Text); }
            set { a_cboCo2Present.Text = Enums.eCO2Present.ToData(value); }
        }
        public Enums.H2SPresent H2SPresent
        {
            get { return Enums.eH2SPresent.ToEnum(a_cboH2sPresent.Text); }
            set { a_cboH2sPresent.Text = Enums.eH2SPresent.ToData(value); }
        }
        public Enums.CompanyMan CompanyMan
        {
            get
            {
                if (a_cboCustomerRepDetails.Text != "") return Enums.eCompanyMan.ToEnum(a_cboCustomerRepDetails.Text);
                else return Enums.eCompanyMan.ToEnum(a_cboOrderedByDetails.Text);
            }
            set
            {
                a_cboCustomerRepDetails.Text = Enums.eCompanyMan.ToData(value);
                a_cboOrderedByDetails.Text = Enums.eCompanyMan.ToData(value);
            }
        }
        public bool IsTrainingJob
        {
            get { return a_chkTrainingJob.Checked; }
            set { a_chkTrainingJob.Checked = value; }
        }
        public bool RiglessOperation
        {
            get { return a_chkRiglessOperation.Checked; }
            set { a_chkRiglessOperation.Checked = value; }
        }
        public Enums.ServiceCoordinator ServiceCoordinator
        {
            get { return Enums.eServiceCoordinator.ToEnum(a_cmbSrvcCoord.Text); }
            set { a_cmbSrvcCoord.Text = Enums.eServiceCoordinator.ToData(value); }
        }
        public Enums.ServicePlanner ServicePlanner
        {
            get { return Enums.eServicePlanner.ToEnum(a_cmbServicePlanner.Text); }
            set { a_cmbServicePlanner.Text = Enums.eServicePlanner.ToData(value); }
        }
        public Enums.LoggingEngineer LoggingEngineer
        {
            get { return Enums.eLoggingEngineer.ToEnum(a_cboEngineer.Text); }
            set { a_cboEngineer.Text = Enums.eLoggingEngineer.ToData(value); }
        }
        public Enums.QualityCoordinator QualityCoordinator
        {
            get { return Enums.eQualityCoordinator.ToEnum(a_cboQualityCoordinator.Text); }
            set { a_cboQualityCoordinator.Text = Enums.eQualityCoordinator.ToData(value); }
        }
        public string SaleNumber
        {
            get { return a_txtSalesOrderNumber.Text; }
            set { a_txtSalesOrderNumber.Text = value; }
        }
        public string ShipToNumber
        {
            get { return a_txtSAPWellId.Text; }
            set { a_txtSAPWellId.Text = value; }
        }
        public string WellName
        {
            get { return a_txtWellName.Text; }
            set { a_txtWellName.Text = value; }
        }
        public string API_UWI()
        {
            a_btnDefaultAPI.PerformClick();
            return a_txtAPI.Text;
        }
        private Enums.Unit.Style _unitStyle = Enums.Unit.Style.NA;
        public Enums.Unit.Style UnitStyle
        {
            get
            {
                return _unitStyle;
            }
            set
            {
                _unitStyle = value;
                switch (_unitStyle)
                {
                    case Enums.Unit.Style.PTTEP:
                        a_uomDrillerDepth.Unit = Enums.Unit.eDistance.ToData(Enums.Unit.Distance.M);
                        //a_uomJobMD.Unit = Enums.Unit.eDistance.ToData(Enums.Unit.Distance.M);
                        //a_uomJobTVD.Unit = Enums.Unit.eDistance.ToData(Enums.Unit.Distance.M);
                        a_uomBHT.Unit = Enums.Unit.eTemperature.ToData(Enums.Unit.Temperature.degF);
                        a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.PSIG);
                        //a_uomWHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.PSIG);
                        //a_uomFluidLevel.Unit = Enums.Unit.eDistance.ToData(Enums.Unit.Distance.M);
                        a_uomMudWt.Unit = Enums.Unit.eWeightMud.ToData(Enums.Unit.WeightMud.LB_GAL);
                        a_uomMudResistivity.Unit = Enums.Unit.eResistivity.ToData(Enums.Unit.Resistivity.OHM_M);
                        a_uomBitSize.Unit = Enums.Unit.eDistance.ToData(Enums.Unit.Distance.IN);
                        a_uomChlorideConc.Unit = Enums.Unit.eConcentration.ToData(Enums.Unit.Concentration.PPM);
                        a_uomMaxDev.Unit = Enums.Unit.eDegree.ToData(Enums.Unit.Degree.DEG);
                        a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.DEG_10M);
                        break;
                    case Enums.Unit.Style.CHEVRON:
                        a_uomDrillerDepth.Unit = Enums.Unit.eDistance.ToData(Enums.Unit.Distance.FT);
                        a_uomBHT.Unit = Enums.Unit.eTemperature.ToData(Enums.Unit.Temperature.degF);
                        a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.PSIG);
                        a_uomMudWt.Unit = Enums.Unit.eWeightMud.ToData(Enums.Unit.WeightMud.LB_GAL);
                        a_uomMudResistivity.Unit = Enums.Unit.eResistivity.ToData(Enums.Unit.Resistivity.OHM_M);
                        a_uomBitSize.Unit = Enums.Unit.eDistance.ToData(Enums.Unit.Distance.IN);
                        a_uomChlorideConc.Unit = Enums.Unit.eConcentration.ToData(Enums.Unit.Concentration.PPM);
                        a_uomMaxDev.Unit = Enums.Unit.eDegree.ToData(Enums.Unit.Degree.DEG);
                        a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.DEG_10M);
                        break;
                }
            }
        }
        public string DrillDepth
        {
            get { return a_uomDrillerDepth.Text; }
            set { a_uomDrillerDepth.Text = value; }
        }
        public string JobMD
        {
            get { return a_uomJobMD.Text; }
            set { a_uomJobMD.Text = value; }
        }
        public string JobTVD
        {
            get { return a_uomJobTVD.Text; }
            set { a_uomJobTVD.Text = value; }
        }
        public string MaxTemp
        {
            get { return a_uomBHT.Text; }
            set { a_uomBHT.Text = value; }
        }
        public string FormationPressure
        {
            get { return a_uomBHP.Text; }
            set { a_uomBHP.Text = value; }
        }
        public string WellheadPressure
        {
            get { return a_uomWHP.Text; }
            set { a_uomWHP.Text = value; }
        }
        public Enums.WellFluid WellFluid
        {
            get { return Enums.eWellFluid.ToEnum(a_cboWellFluid.Text); }
            set { a_cboWellFluid.Text = Enums.eWellFluid.ToData(value); }
        }
        public string FluidLevel
        {
            get { return a_uomFluidLevel.Text; }
            set { a_uomFluidLevel.Text = value; }
        }
        public string MudWeight
        {
            get { return a_uomMudWt.Text; }
            set { a_uomMudWt.Text = value; }
        }
        public string MudResistivity
        {
            get { return a_uomMudResistivity.Text; }
            set { a_uomMudResistivity.Text = value; }
        }
        public string MudResTemp
        {
            get { return a_uomMudResistivityMD.Text; }
            set { a_uomMudResistivityMD.Text = value; }
        }
        public string FilterateResistivity
        {
            get { return a_uomFilterateResistivity.Text; }
            set { a_uomFilterateResistivity.Text = value; }
        }
        public string FilterateResTemp
        {
            get { return a_uomFilterateResistivityMD.Text; }
            set { a_uomFilterateResistivityMD.Text = value; }
        }
        public string CakeResistivity
        {
            get { return a_uomCakeResistivity.Text; }
            set { a_uomCakeResistivity.Text = value; }
        }
        public string CakeResTemp
        {
            get { return a_uomCakeResistivityMD.Text; }
            set { a_uomCakeResistivityMD.Text = value; }
        }
        public string BitSize
        {
            get { return a_uomBitSize.Text; }
            set { a_uomBitSize.Text = value; }
        }
        public string ChlorideConcentration
        {
            get { return a_uomChlorideConc.Text; }
            set { a_uomChlorideConc.Text = value; }
        }
        public string MinID
        {
            get { return a_uomMinID.Text; }
            set { a_uomMinID.Text = value; }
        }
        public string MinIDDepth
        {
            get { return a_uomMinIDMD.Text; }
            set { a_uomMinIDMD.Text = value; }
        }
        public string MaxDeviation
        {
            get { return a_uomMaxDev.Text; }
            set { a_uomMaxDev.Text = value; }
        }
        public string MaxDevDepth
        {
            get { return a_uomMaxDevMD.Text; }
            set { a_uomMaxDevMD.Text = value; }
        }
        public string KickoffDepth
        {
            get { return a_uomKickDepth.Text; }
            set { a_uomKickDepth.Text = value; }
        }
        public string MaxDogleg
        {
            get { return a_uomMaxDogLeg.Text; }
            set { a_uomMaxDogLeg.Text = value; }
        }
        public string MaxDoglegDepth
        {
            get { return a_uomMaxDogLegMD.Text; }
            set { a_uomMaxDogLegMD.Text = value; }
        }
        public string WellDirectionTD
        {
            get { return a_uomWellDirTD.Text; }
            set { a_uomWellDirTD.Text = value; }
        }
        public string WellDeviationTD
        {
            get { return a_uomDeviationTD.Text; }
            set { a_uomDeviationTD.Text = value; }
        }
        public string WaterDepth
        {
            get { return a_uomWaterDepth.Text; }
            set { a_uomWaterDepth.Text = value; }
        }
        public string SeaBedTemp
        {
            get { return a_uomSeaBedTemp.Text; }
            set { a_uomSeaBedTemp.Text = value; }
        }
        public bool ShowPerfInterval
        {
            get { return a_chkShowPerfData.Checked; }
            set { a_chkShowPerfData.Checked = value; }
        }
        public object Perforation
        {
            get { return a_dgPerforation.DataSource; }
            set { a_dgPerforation.DataSource = value; }
        }
        public object Services
        {
            get { return a_dgServices.DataSource; }
            set { a_dgServices.DataSource = value; }
        }
        public object JobTubulars
        {
            get { return a_dgTubPerf.DataSource; }
            set { a_dgTubPerf.DataSource = value; }
        }
        
        /*public Word.Document GenerateHitList()
        {
            a_Btn_GenerateHitList.PerformClick();
            return new Word.Document();
            //Word.Document doc = Word.
        }*/

        public void AddPerforation(SummitLib.PERFROW[] PerfRuns)
        {
            a_btnPerforation.PerformClickAsync();

            List<IntPtr> hWndPerf = new List<IntPtr>();
            int i = 30;
            while (hWndPerf.Count == 0 & i > 0)
            {
                hWndPerf = DienLib.WinAPI.FindWindowLike(Process.GetCurrentProcess(), "Perforation", DienLib.FindCulture.EXACT_MATCH);
                i--; System.Threading.Thread.Sleep(1000);
            }

            if (hWndPerf.Count == 0) throw new InvalidOperationException("Timed Out when AddPerforation ! Can not find Window \"Perforation\"");

            PerfLib perfLib = new PerfLib((Form)(Control.FromHandle(hWndPerf[0])));

            //perfLib.AddPerforation(1, 2, 1234, 1235, Enums.GunSize._2IN, Enums.SPF._6SPF, Enums.Polarity.POSITIVE, "FIRED OK !");
            foreach (SummitLib.PERFROW perfRow in PerfRuns)
            {
                perfLib.AddPerforation(perfRow);
                System.Threading.Thread.Sleep(500);
            }
            perfLib.PerformClickOK();
            //System.Data.DataSet dsPerf = (System.Data.DataSet)a_dgPerforation.DataSource;

            //System.Data.DataTable dtPerf = dsPerf.Tables[0];
            //dtPerforations.Rows.Add("OID", "JOB_OID", "LOG_RUN_TYPE_CD", "GUN_NBR", "RUN_NBR", "BTM_MD", "TOP_MD", "TOOL_SZ", "SHOT_DENS", "PLTRY", "CMNT");
            //dtPerforations.Rows.Add(null, null, null, "1", "1", "1234", "1230", "2", "6", "+", "FIRED OK - HEHEHE !");
            //System.Data.DataRow drPerf = dtPerf.Rows[0];
            //drPerf.ItemArray[10] += "HEHEHE";
            //DienLib.WinAPI.WriteNotePad((string)drPerf.ItemArray[10]);
        }

        public void AddService(SummitLib.SERVICEROW[] NonPerfRuns)
        {
            a_btnServices.PerformClickAsync();

            List<IntPtr> hWndService = new List<IntPtr>();
            int i = 30;
            while (hWndService.Count == 0 & i > 0)
            {
                hWndService = DienLib.WinAPI.FindWindowLike(Process.GetCurrentProcess(), "Services", DienLib.FindCulture.EXACT_MATCH);
                i--; System.Threading.Thread.Sleep(1000);
            }

            if (hWndService.Count == 0) throw new InvalidOperationException("Timed Out when AddServices ! Can not find Window \"Services\"");

            ServiceLib serviceLib = new ServiceLib((Form)(Control.FromHandle(hWndService[0])));

            //WinAPI.WriteNotePad(serviceLib.ToString());

            serviceLib.AddServices(NonPerfRuns, 500);
            
            serviceLib.PerformClickOK();
        }

        public void ActivateTabPage1()
        {
            a_TabPage1.PerformClick();
        }
        public void ActivateTabPage2()
        {
            if (!(this.CurrentPage == DienLib.SummitLib.JobLib.JobPage.PAGE2_PREPARE))
            {  // Page 2 chua duoc chon
                MessageBox.Show("Please Choose PAGE2 before Click this button. You are now on : \"" + this.CurrentPageName + "\"", "WARNING : Page2 not active !");
                throw new InvalidOperationException("Can not Activate Page 2 Automatically, you have to choose Page 2 by your mouse click !");
            }

            if (a_dgTubPerf.DataMember == String.Empty)
            {
                MessageBox.Show("Please choose PAGE2 : SERVICE DELIVERY first before call ActivateTabPage2 !", "WARNING : Page2 not ready !");
                throw new InvalidOperationException("PAGE2 not manually choose before then PerfTubeGrid not created yet");
            }
            a_TabPage2.PerformClick();
        }

        public void ActivateTabPage3()
        {
            a_TabPage3.PerformClick();
        }

        public void AddJobTubular(List<PERFROW> perfTable)
        {
            a_btnPerforation.PerformClick();

            using (PerfLib perfLib = PerfLib.FindPerfLib())
            {
                foreach (PERFROW perfRow in perfTable)
                {
                    perfLib.AddPerforation(perfRow);
                }
                perfLib.PerformClickOK();
            }
        }

        public enum JobPage { PAGE1_HEADER, PAGE2_PREPARE, PAGE3_DOJOB, PAGE4_REVIEW, PAGE5_TICKET };
        private string[] JobPageArr = { "PAGE1_HEADER", "PAGE2_PREPARE", "PAGE3_DOJOB", "PAGE4_REVIEW", "PAGE5_TICKET" };
        public JobPage CurrentPage
        {
            get { return (JobPage)a_TabControlMain.SelectedIndex; }
        }
        public string CurrentPageName
        {
            get { return JobPageArr[a_TabControlMain.SelectedIndex]; }
        }

        public void FillExplosiveSafetyList()
        {
            a_btn_ExplosiveSafety.PerformClickAsync();

            using (ExpSafeLib expSafeLib = ExpSafeLib.FindExpSafeLib())
            {
                expSafeLib.PerformFillFullYes();
                expSafeLib.PerformClickOK();
            }
        }

        #region DISPOSE METHOD
        // Dispose() calls Dispose(true)
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        // NOTE: Leave out the finalizer altogether if this class doesn't 
        // own unmanaged resources itself, but leave the other methods
        // exactly as they are. 
        ~JobLib()
        {
            // Finalizer calls Dispose(false)
            Dispose(false);
        }

        // The bulk of the clean-up code is implemented in Dispose(bool)
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {   // Get in HERE if called explicitly, otherwise not need to enter HERE, after Destructor Managed Var which is Pointer to Real Object will fall out of stack automatically (like var out of scope)
                // free managed resources, (detach event ?)
                if (this._form != null) this._form = null; // Khong keu this._form.Dispose vi Reference toi _form. Ngoai ra do pass reference nen this._form = null khong anh huong gi toi object goc
                if (this.a_btn_ExplosiveSafety != null) this.a_btn_ExplosiveSafety = null;
                if (this.a_Btn_GenerateHitList != null) this.a_Btn_GenerateHitList = null;
                if (this.a_Btn_KpiEjcs != null) this.a_Btn_KpiEjcs = null;
                if (this.a_Btn_ServiceDeliveryDelivery != null) this.a_Btn_ServiceDeliveryDelivery = null;
                if (this.a_btnNewWell != null) this.a_btnNewWell = null;
                if (this.a_btnPerforation != null) this.a_btnPerforation = null;
                if (this.a_btnSafetyMeeting != null) this.a_btnSafetyMeeting = null;
                if (this.a_btnServices != null) this.a_btnServices = null;
                if (this.a_cboCo2Present != null) this.a_cboCo2Present = null;
                if (this.a_cboCompany != null) this.a_cboCompany = null;
                if (this.a_cboCountry != null) this.a_cboCountry = null;
                if (this.a_cboCurrentJobStatus != null) this.a_cboCurrentJobStatus = null;
                if (this.a_cboCustomerRepDetails != null) this.a_cboCustomerRepDetails = null;
                if (this.a_cboEngineer != null) this.a_cboEngineer = null;
                if (this.a_cboField != null) this.a_cboField = null;
                if (this.a_cboH2sPresent != null) this.a_cboH2sPresent = null;
                if (this.a_cboJobType != null) this.a_cboJobType = null;
                if (this.a_cboJobWellType != null) this.a_cboJobWellType = null;
                if (this.a_cboLease != null) this.a_cboLease = null;
                if (this.a_cboLocation != null) this.a_cboLocation = null;
                if (this.a_cboOrderedByDetails != null) this.a_cboOrderedByDetails = null;
                if (this.a_cboPrimaryServiceCenter != null) this.a_cboPrimaryServiceCenter = null;
                if (this.a_cboQualityCoordinator != null) this.a_cboQualityCoordinator = null;
                if (this.a_cboSecondaryServiceCenter != null) this.a_cboSecondaryServiceCenter = null;
                if (this.a_cboState != null) this.a_cboState = null;
                if (this.a_cboWellFluid != null) this.a_cboWellFluid = null;
                if (this.a_chkRiglessOperation != null) this.a_chkRiglessOperation = null;
                if (this.a_chkShowPerfData != null) this.a_chkShowPerfData = null;
                if (this.a_chkTrainingJob != null) this.a_chkTrainingJob = null;
                if (this.a_cmbServicePlanner != null) this.a_cmbServicePlanner = null;
                if (this.a_cmbSrvcCoord != null) this.a_cmbSrvcCoord = null;
                if (this.a_dgPerforation != null) this.a_dgPerforation = null;
                if (this.a_dgServices != null) this.a_dgServices = null;
                if (this.a_dgTubPerf != null) this.a_dgTubPerf = null;
                if (this.a_lblBHP != null) this.a_lblBHP = null;
                if (this.a_lblFax != null) this.a_lblFax = null;
                if (this.a_lblPhone != null) this.a_lblPhone = null;
                if (this.a_TabControlMain != null) this.a_TabControlMain = null;
                if (this.a_TabPage_Services != null) this.a_TabPage_Services = null;
                if (this.a_TabPage1 != null) this.a_TabPage1 = null;
                if (this.a_TabPage2 != null) this.a_TabPage2 = null;
                if (this.a_TabPage3 != null) this.a_TabPage3 = null;
                if (this.a_TabPage4 != null) this.a_TabPage4 = null;
                if (this.a_TabPage5 != null) this.a_TabPage5 = null;
                if (this.a_tbbCancel != null) this.a_tbbCancel = null;
                if (this.a_tbbEquipmentSelector != null) this.a_tbbEquipmentSelector = null;
                if (this.a_tbbJobMaterials != null) this.a_tbbJobMaterials = null;
                if (this.a_tbbJobTimes != null) this.a_tbbJobTimes = null;
                if (this.a_tbbPersonnel != null) this.a_tbbPersonnel = null;
                if (this.a_tbbSave != null) this.a_tbbSave = null;
                if (this.a_tbbSaveExit != null) this.a_tbbSaveExit = null;
                if (this.a_ToolBarTop != null) this.a_ToolBarTop = null;
                if (this.a_txtAPI != null) this.a_txtAPI = null;
                if (this.a_txtQuoteNumber != null) this.a_txtQuoteNumber = null;
                if (this.a_txtSalesOrderNumber != null) this.a_txtSalesOrderNumber = null;
                if (this.a_txtSAPWellId != null) this.a_txtSAPWellId = null;
                if (this.a_txtWellName != null) this.a_txtWellName = null;
                if (this.a_UcCustomerInfo != null) this.a_UcCustomerInfo = null;
                if (this.a_ucJobSupervisor != null) this.a_ucJobSupervisor = null;
                if (this.a_ucServiceCoordinatorCtrl != null) this.a_ucServiceCoordinatorCtrl = null;

                if (this.a_ucWellDataCtrl != null) this.a_ucWellDataCtrl = null;
                if (this.a_ucWellIdentification != null) this.a_ucWellIdentification = null;
                if (this.a_uomBHP != null) this.a_uomBHP = null;
                if (this.a_uomBHT != null) this.a_uomBHT = null;
                if (this.a_uomBitSize != null) this.a_uomBitSize = null;
                if (this.a_uomCakeResistivity != null) this.a_uomCakeResistivity = null;
                if (this.a_uomCakeResistivityMD != null) this.a_uomCakeResistivityMD = null;
                if (this.a_uomChlorideConc != null) this.a_uomChlorideConc = null;
                if (this.a_uomDeviationTD != null) this.a_uomDeviationTD = null;
                if (this.a_uomDrillerDepth != null) this.a_uomDrillerDepth = null;
                if (this.a_uomFilterateResistivity != null) this.a_uomFilterateResistivity = null;
                if (this.a_uomFilterateResistivityMD != null) this.a_uomFilterateResistivityMD = null;
                if (this.a_uomFluidLevel != null) this.a_uomFluidLevel = null;
                if (this.a_uomJobMD != null) this.a_uomJobMD = null;
                if (this.a_uomJobTVD != null) this.a_uomJobTVD = null;
                if (this.a_uomKickDepth != null) this.a_uomKickDepth = null;
                if (this.a_uomMaxDev != null) this.a_uomMaxDev = null;
                if (this.a_uomMaxDevMD != null) this.a_uomMaxDevMD = null;
                if (this.a_uomMaxDogLeg != null) this.a_uomMaxDogLeg = null;
                if (this.a_uomMaxDogLegMD != null) this.a_uomMaxDogLegMD = null;
                if (this.a_uomMinID != null) this.a_uomMinID = null;
                if (this.a_uomMinIDMD != null) this.a_uomMinIDMD = null;
                if (this.a_uomMudResistivity != null) this.a_uomMudResistivity = null;
                if (this.a_uomMudResistivityMD != null) this.a_uomMudResistivityMD = null;
                if (this.a_uomMudWt != null) this.a_uomMudWt = null;
                if (this.a_uomSeaBedTemp != null) this.a_uomSeaBedTemp = null;
                if (this.a_uomWaterDepth != null) this.a_uomWaterDepth = null;
                if (this.a_uomWellDirTD != null) this.a_uomWellDirTD = null;
                if (this.a_uomWHP != null) this.a_uomWHP = null;

                if (this.JobPageArr != null) this.JobPageArr = null;
                //DienLib.WinAPI.WriteNotePad("KEKEKEKE");
            }

            /* free native resources if there are any.
            if (nativeResource != IntPtr.Zero) 
            {
                Marshal.FreeHGlobal(nativeResource);
                nativeResource = IntPtr.Zero;
            }*/
        }
        #endregion
    }
}













#if DEBUG
namespace DienLib.SummitLib.UnitTest
{
    public class JobLib
    {
        DienLib.SummitLib.JobLib _jobLib;
        UnitTextBox a_uomBHP;
        UnitTextBox a_uomMaxDogLeg;
        public JobLib(DienLib.SummitLib.JobLib jobLib)
        {
            _jobLib = jobLib;
            a_uomBHP = DienLib.Reflector.GetField<UnitTextBox>(_jobLib, "a_uomBHP");
            a_uomMaxDogLeg = DienLib.Reflector.GetField<UnitTextBox>(_jobLib, "a_uomBHP");
        }

        /// <summary>
        /// Draw a High-lighted Border on uomBHP Text & Unit with expanded as user request to test if the border is right position or not
        /// If not right position then will se artifact left on the screen
        /// </summary>
        /// <param name="expandcode">eg : "1234" expand to lef 1, right 2, top 3, bottom 4 (in that order)</param>
        [Conditional("DEBUG")]
        public void _DebugDrawBorder_uomBHP_ExpandClientRectange(string expandcode)
        {
            UnitTextBox.left = Convert.ToInt32(expandcode[0].ToString());
            UnitTextBox.right = Convert.ToInt32(expandcode[1].ToString());
            UnitTextBox.top = Convert.ToInt32(expandcode[2].ToString());
            UnitTextBox.bot = Convert.ToInt32(expandcode[3].ToString());

            a_uomBHP.Unit = "psig";
            a_uomBHP.Text = "1234";
        }

        /// <summary>
        /// Test Change All kind of Unit
        /// </summary>
        [Conditional("DEBUG")]
        public void _DebugDrawBorder_UnitTextBox_TestAllUnit()
        {
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.ATM); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.BAR); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.kPA); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.kPAG); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.MPA); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.MPAG); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.NA); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.PA); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.PSI); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.PSIA); System.Threading.Thread.Sleep(300);
            a_uomBHP.Unit = Enums.Unit.ePressure.ToData(Enums.Unit.Pressure.PSIG); System.Threading.Thread.Sleep(300);

            a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.DEG_100FT); System.Threading.Thread.Sleep(300);
            a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.DEG_10M); System.Threading.Thread.Sleep(300);
            a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.DEG_30M); System.Threading.Thread.Sleep(300);
            a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.DEG_1000FT); System.Threading.Thread.Sleep(300);
            a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.NA); System.Threading.Thread.Sleep(300);
            a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.RAD_100FT); System.Threading.Thread.Sleep(300);
            a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.RAD_10M); System.Threading.Thread.Sleep(300);
            a_uomMaxDogLeg.Unit = Enums.Unit.eDogLeg.ToData(Enums.Unit.DogLeg.RAD_30M); System.Threading.Thread.Sleep(300);
        }


        bool once = true;
        /// <summary>
        /// Expande the uomBHP bigger to see all nested control : UnitTextBox, PanelBorder, SplitContainer, SplitContainer.Panel1 (PanelBorderTextBoxState, TextBox), SplitContainerPanel2(Label)
        /// </summary>
        /// <param name="p"></param>
        [Conditional("DEBUG")]
        public void _DebugDrawBorder_UnitTextBox_ExpandAll(System.Drawing.Point p)
        {
            if (once)
            {
                once = false;

                //UserControl a_ucWellDataCtrl = DienLib.Reflector.GetField<UserControl>(_jobLib, "a_ucWellDataCtrl");
                //object obj = DienLib.Reflector.GetField<object>(a_ucWellDataCtrl, "_uomWHP");
                //Label lbl = DienLib.Reflector.GetField<Label>(a_ucWellDataCtrl, "_lblFilterateResistivity");

                object obj = DienLib.Reflector.GetNestedField<object>(_jobLib, "a_ucWellDataCtrl", "_uomWHP");
                Label lbl = DienLib.Reflector.GetNestedField<Label>(_jobLib, "a_ucWellDataCtrl", "_lblFilterateResistivity");

                DienLib.Reflector.SetProperty<bool>(obj, "Visible", false);
                lbl.Visible = false;
            }

            a_uomBHP._DebugDrawBorder_UnitTextBox_ExpandAll(p);
        }

        [Conditional("DEBUG")]
        public void _DebugDrawBorder_UnitTextBox_ExpandPartial(System.Drawing.Point p)
        {
            if (once)
            {
                once = false;

                //UserControl a_ucWellDataCtrl = DienLib.Reflector.GetField<UserControl>(_jobLib, "a_ucWellDataCtrl");
                //object obj = DienLib.Reflector.GetField<object>(a_ucWellDataCtrl, "_uomWHP");
                //Label lbl = DienLib.Reflector.GetField<Label>(a_ucWellDataCtrl, "_lblFilterateResistivity");

                object obj = DienLib.Reflector.GetNestedField<object>(_jobLib, "a_ucWellDataCtrl", "_uomWHP");
                Label lbl = DienLib.Reflector.GetNestedField<Label>(_jobLib, "a_ucWellDataCtrl", "_lblFilterateResistivity");

                DienLib.Reflector.SetProperty<bool>(obj, "Visible", false);
                lbl.Visible = false;
            }

            a_uomBHP._DebugDrawBorder_UnitTextBox_ExpandPartial(p);
        }
    }
}
#endif


